package com.zmd.test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.jupiter.api.Test;

import com.zmd.bean.User;
import com.zmd.dao.UserDao;

class test {

	@Test
	void test0() throws IOException {
		String resource = "mybatis-config.xml";
		InputStream inputStream = Resources.getResourceAsStream(resource);
		SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
		
		SqlSession session = sqlSessionFactory.openSession();
		UserDao userDao = session.getMapper(UserDao.class);
		User user0 = userDao.getUserById(13);
		System.out.println("" + user0.getId() + "," + user0.getName());
		
		List<User> list = userDao.getAllUsers();
		for (User user1 : list) {
			System.out.println("" + user1.getId() + "," + user1.getName());
		}
	}

}
